<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php 
	require('components/common/loader.php');
	function getMenuTree()
	{
		global $siteAdmin;
		if($_GET['p'] > 1)
		{
			$sitemap = $siteAdmin->getSitemapTree(SITE_ID, $_GET['p']);
			$tree = getSitemapSubitemsJSON($sitemap);
		}
		else
		{ $tree = getRootLevel(); }
		return $tree;
	}
	
	function getRootLevel()
	{
		global $katana;
		global $commander;
		global $siteAdmin;
		global $txt;
		
		$i = 0;
		
		$sitemap	= $siteAdmin->getSitemapTree(SITE_ID, 0);
		$tree[$i]['attr']['id'] = 'sitemap-site';
		$tree[$i]['attr']['rel'] = 'site';
		$tree[$i]['data']['title'] = $katana->getTitle().' - '.ucfirst($txt->getWord('sitemap'));
		$tree[$i]['data']['icon'] = SYSICONS_URL.'treemenu/web_16.png';
		$tree[$i]['data']['attr']['rev'] = $item['id'];
		$tree[$i]['data']['attr']['href'] = '?con=1';
		if(intval($commander->getCon() == 1))
		{ $tree[$i]['children'] = getSitemapSubitemsJSON($sitemap); }
		if(intval($commander->getCon() < 2))
		{ $tree[$i]['state'] = 'open'; }
		$i++;
		
		if(count($katana->getActiveCores()) > 0)
		{
			foreach($katana->ActiveCores as $core)
			{
				if($core->getId() > 1)
				{
					$tree[$i]['attr']['id'] = 'con_'.$core->getId();
					$tree[$i]['attr']['rel'] = $core->getHandle();
					$tree[$i]['data']['title'] = ucfirst($txt->getWord($core->getTitle()));
					$tree[$i]['data']['icon'] = SYSICONS_URL.'treemenu/'.$core->getHandle().'_16.png';
					$tree[$i]['data']['attr']['href'] = '?con='.$core->getId();
					
					switch($core->getId())
					{
						case 2 : //Access Control
							$tree[$i]['data']['attr']['href'] .= '&list=user';
							if(intval($commander->getCon() == $core->getId()))
							{ $tree[$i]['children'] = getAcessControllSubitemsJSON($core->getId()); }
						break;
						case 3 : //Form Manager
							$tree[$i]['data']['attr']['href'] .= '&list=form';
							if(intval($commander->getCon() == $core->getId()))
							{ $tree[$i]['children'] = getFormsJSON($core->getId()); }
						break;
						case 6 : //Advertiser
							$tree[$i]['data']['attr']['href'] .= '&list=type';
							if(intval($commander->getCon() == $core->getId()))
							{ $tree[$i]['children'] = getAdvertiserSubitemsJSON($core->getId()); }
						break;
						case 8 : //Shop
							if(intval($commander->getCon() == $core->getId()))
							{ $tree[$i]['children'] = getShopSubitemsJSON($core->getId()); }
						break;
						case 9 : //Survey
							//$tree[$i]['children'] = getSurveySubitemsJSON($con);  
						break;
						case 10: //Fleet
							if(intval($commander->getCon() == $core->getId()))
							{ $tree[$i]['children'] = getFleetSubitemsJSON($core->getId());   }
						break;
					}
					$i++;
				}
			}
		}
		return $tree;
	}
	
	function getSitemapSubitemsJSON($sitemap, $con=1, $IdPrefix='')
    {
		global $siteAdmin;
		global $commander;
        if($sitemap)
        {
			$i = 0;
            foreach($sitemap as $item)
            {
				$node[$i]['attr']['id'] = $IdPrefix.'m_'.$item['id'];
				$node[$i]['data']['title'] = $item['title'];
				$node[$i]['data']['attr']['rev'] = $item['id'];
				$node[$i]['data']['attr']['href'] = '?con='.$con.'&m='.$item['id'].'&p='.$item['parent_id'].'';
				$node[$i]['data']['attr']['itemid'] = $item['id'];
				$node[$i]['data']['attr']['oldparent'] = $item['parent_id'];
				
				$subItems = $siteAdmin->getSitemapTree(SITE_ID, $item['id']);
				
				if(count($subItems) > 0)
				{
					$node[$i]['attr']['rel'] = 'sitemap-item-folder';
					$node[$i]['children'] = getSitemapSubitemsJSON($subItems, $con, $IdPrefix);  
					if(($con == $commander->getCon()) && (($_REQUEST['m'] == $item['parent_id']) || ($item['parent_id'] < 2) || ($i == 0) || ($_REQUEST['m'] == $item['id'])))
					{ 
						$node[$i]['state'] = 'open'; 
						$node[$i]['attr']['class'] = 'open';
					}
					else
					{ $node[$i]['state'] = 'closed';  }
				}
				else
				{  $node[$i]['attr']['rel'] = 'sitemap-item'; }
                $i++;
            }
        }
        return $node;
    }
	
	function getFormsJSON($con)
    {
		global $fc;
		$i = 0;
		if($fc->getForms())
		{
			foreach($fc->getForms() as $item)
			{
				$node[$i]['attr']['id'] = 'form_'.$item->getId();
				$node[$i]['attr']['rel'] = 'form';
				$node[$i]['data']['title'] = $item->getTitle();
				$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/form_16.png';
				$node[$i]['data']['attr']['href'] = '?con='.$con.'&form='.$item->getId().'';
				$i++;
			}
		} 
        return $node;
    }
	
	function getAdvertiserSubitemsJSON($con)
    {
		global $commander;
		global $katana;
		global $adc;
		global $txt;
		
		$i = 0;
		$node[$i]['attr']['id'] = 'adtypes';
		$node[$i]['attr']['rel'] = 'adtypes';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('ad_types')).' ('.intval(count($adc->getAdTypes())).')';
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_green_16.gif';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=type';
		if(intval($_REQUEST['type']) > 0)
		{ 
			$node[$i]['state'] = 'open'; 
			$node[$i]['attr']['class'] = 'jstree-open';
		}
		
		$j = 0;
		if($adc->getAdTypes())
		{
			foreach($adc->getAdTypes() as $item)
			{
				$node[$i]['children'][$j]['attr']['id'] = 'adtype_'.$item->getId();
				$node[$i]['children'][$j]['attr']['rel'] = 'adtype';
				$node[$i]['children'][$j]['data']['title'] = $item->getTitle();
				$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/file_doc_16.gif';
				$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&editor=type&type='.$item->getId().'';
				$j++;
			}
		}
		$i++;
		
		// Ad Categories
		$node[$i]['attr']['id'] = 'adcats';
		$node[$i]['attr']['rel'] = 'adcats';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('ad_categories')).' ('.intval(count($adc->getAdCats())).')';
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_blue_16.gif';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=cat';
		if(intval($_REQUEST['cat']) > 0)
		{ 
			$node[$i]['state'] = 'open'; 
			$node[$i]['attr']['class'] = 'jstree-open';
		}
		$node[$i]['children'] = getAdCatSubitemsJSON($con);
		$i++;
		
		// Ad Brands
		$node[$i]['attr']['id'] = 'adbrands';
		$node[$i]['attr']['rel'] = 'adbrands';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('brands'));
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_grey_16.gif';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=adbrand';
		if(intval($_REQUEST['brand']) > 0)
		{ 
			$node[$i]['state'] = 'open'; 
			$node[$i]['attr']['class'] = 'jstree-open';
		}

		if($adc->getSetting('model-manager'))
		{
			$i++;
			$node[$i]['attr']['id'] = 'admodels';
			$node[$i]['attr']['rel'] = 'admodels';
			$node[$i]['data']['title'] = ucfirst($txt->getWord('models'));
			$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_green_16.gif';
			$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=model';
			if(intval($_REQUEST['brand']) > 0)
			{ 
				$node[$i]['state'] = 'open'; 
				$node[$i]['attr']['class'] = 'jstree-open';
			}
		}
		
		$i++;
		$node[$i]['attr']['id'] = 'ads';
		$node[$i]['attr']['rel'] = 'ads';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('ads'));
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_green_16.gif';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=ad&user='.$_GET['user'];
		$node[$i]['children'] = getAdsSubitemsJSON($con);
        return $node;
    }
	
	function getAdCatSubitemsJSON($con, $parentId=0)
    {
		global $commander;
		global $katana;
		global $adc;
		global $txt;
		
		$j = 0;
		if($adc->getAdCats())
		{
			if($adc->getAdTypes())
			{
				foreach($adc->getAdTypes() as $pitem)
				{
					$node[$j]['attr']['id'] = 'adcat_type_'.$pitem->getId();
					$node[$j]['attr']['rel'] = 'adcat_type';
					$node[$j]['data']['title'] = $pitem->getTitle();
					$node[$j]['data']['icon'] = SYSICONS_URL.'treemenu/folder_green_16.gif';
					$node[$j]['data']['attr']['href'] = '?con='.$con.'&list=cat&typeId='.$pitem->getId();
					$k=0;
					foreach($adc->getAdCats() as $item)
					{
						if($item->getTypeId() == $pitem->getId())
						{
							if($item->getParentId() == 0)
							{
								$node[$j]['children'][$k]['attr']['id'] = 'adcat_'.$item->getId();
								$node[$j]['children'][$k]['attr']['rel'] = 'adcat';
								$node[$j]['children'][$k]['data']['title'] = $item->getTitle();
								$node[$j]['children'][$k]['data']['icon'] = SYSICONS_URL.'treemenu/pda_black_16.png';
								$node[$j]['children'][$k]['data']['attr']['href'] = '?con='.$con.'&editor=cat&cat='.$item->getId().'';

								$l = 0;
								foreach($adc->getAdCats() as $subitem)
								{
									if($subitem->getParentId() == $item->getId())
									{
										$node[$j]['children'][$k]['children'][$l]['attr']['id'] = 'adcat_'.$subitem->getId();
										$node[$j]['children'][$k]['children'][$l]['attr']['rel'] = 'adcat';
										$node[$j]['children'][$k]['children'][$l]['data']['title'] = $subitem->getTitle();
										$node[$j]['children'][$k]['children'][$l]['data']['icon'] = SYSICONS_URL.'treemenu/pda_black_16.png';
										$node[$j]['children'][$k]['children'][$l]['data']['attr']['href'] = '?con='.$con.'&editor=cat&cat='.$subitem->getId().'';
										$l++;
									}
								}
								$k++;
							}
						}
					}
					$j++;
				}
			}
			else
			{
				foreach($adc->getAdCats() as $item)
				{
					if($item->getTypeId() == $pitem->getId())
					{
						$node[$j]['attr']['id'] = 'adcat_'.$item->getId();
						$node[$j]['attr']['rel'] = 'adcat';
						$node[$j]['data']['title'] = $item->getTitle();
						$node[$j]['data']['icon'] = SYSICONS_URL.'treemenu/pda_black_16.png';
						$node[$j]['data']['attr']['href'] = '?con='.$con.'&cat='.$item->getId().'';
					}
				}
				$j++;
			}
		}
		return $node;
    }
	
	function getAdsSubitemsJSON($con, $parentId=0)
    {
		global $commander;
		global $katana;
		global $adc;
		global $txt;
		
		$j = 0;
		if($adc->getAdCats())
		{
			if($adc->getAdTypes())
			{
				foreach($adc->getAdTypes() as $pitem)
				{
					$node[$j]['attr']['id'] = 'ad_typeId_'.$pitem->getId();
					$node[$j]['attr']['rel'] = 'ad_typeId';
					$node[$j]['data']['title'] = $pitem->getTitle().' ('.$pitem->getAdsCount().')';
					$node[$j]['data']['icon'] = SYSICONS_URL.'treemenu/folder_green_16.gif';
					$node[$j]['data']['attr']['href'] = '?con='.$con.'&list=ad&typeId='.$pitem->getId().'&user='.$_GET['user'];
					$k=0;
					foreach($adc->getAdCats() as $item)
					{
						if($item->getTypeId() == $pitem->getId())
						{
							if($item->getParentId() == 0)
							{
								$node[$j]['children'][$k]['attr']['id'] = 'ad_catId_'.$item->getId();
								$node[$j]['children'][$k]['attr']['rel'] = 'ad_catId';
								$node[$j]['children'][$k]['data']['title'] = $item->getTitle().' ('.$item->getAdsCount().')';
								$node[$j]['children'][$k]['data']['icon'] = SYSICONS_URL.'treemenu/folder_blue_16.png';
								$node[$j]['children'][$k]['data']['attr']['href'] = '?con='.$con.'&list=ad&catId='.$item->getId().'&user='.$_GET['user'];
								
								$l = 0;
								foreach($adc->getAdCats() as $subitem)
								{
									if($subitem->getParentId() == $item->getId())
									{
										$node[$j]['children'][$k]['children'][$l]['attr']['id'] = 'ad_catId_'.$subitem->getId();
										$node[$j]['children'][$k]['children'][$l]['attr']['rel'] = 'ad_catId';
										$node[$j]['children'][$k]['children'][$l]['data']['title'] = $subitem->getTitle().' ('.$subitem->getAdsCount().')';
										$node[$j]['children'][$k]['children'][$l]['data']['icon'] = SYSICONS_URL.'treemenu/folder_blue_16.png';
										$node[$j]['children'][$k]['children'][$l]['data']['attr']['href'] = '?con='.$con.'&list=ad&catId='.$subitem->getId().'&user='.$_GET['user'];
										$l++;
									}
								}
								$k++;
							}
						}
					}
					$j++;
				}
			}
			else
			{
				foreach($adc->getAdCats() as $item)
				{
					if($item->getTypeId() == $pitem->getId())
					{
						$node[$j]['attr']['id'] = 'ad_catId_'.$item->getId();
						$node[$j]['attr']['rel'] = 'ad_catId';
						$node[$j]['data']['title'] = $item->getTitle().' ('.$item->getAdsCount().')';
						$node[$j]['data']['icon'] = SYSICONS_URL.'treemenu/folder_blue_16.png';
						$node[$j]['data']['attr']['href'] = '?con='.$con.'&list=ad&catId='.$item->getId().'&user='.$_GET['user'];
					}
				}
				$j++;
			}
		}
		
		$node[$j]['attr']['id'] = 'ad_archived';
		$node[$j]['attr']['rel'] = 'ad_archived';
		$node[$j]['data']['title'] = ucfirst($txt->getWord('archived'));
		$node[$j]['data']['icon'] = SYSICONS_URL.'treemenu/archive_16.png';
		$node[$j]['data']['attr']['href'] = '?con='.$con.'&list=ad&archived=1&user='.$_GET['user'];
		$j++;
		
		$node[$j]['attr']['id'] = 'ad_deleted';
		$node[$j]['attr']['rel'] = 'ad_deleted';
		$node[$j]['data']['title'] = ucfirst($txt->getWord('deleted'));
		$node[$j]['data']['icon'] = SYSICONS_URL.'treemenu/trash_16.png';
		$node[$j]['data']['attr']['href'] = '?con='.$con.'&list=ad&deleted=1&user='.$_GET['user'];
		$j++;
		
		return $node;
    }
	
	function getShopSubitemsJSON($con)
    {
		global $siteAdmin;
		global $commander;
		global $katana;
		global $shop;
		global $txt;
		
		$i = 0;
		
		if($shop->getGlobalSetting('import'))
		{
			$node[$i]['attr']['id'] = 'exe';
			$node[$i]['attr']['rel'] = 'exe';
			$node[$i]['data']['title'] = 'Import/Export';
			$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/reload_16.gif';
			$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=exe';
			if($_REQUEST['list'] == 'exe')
			{ $node[$i]['state'] = 'open'; }
			
			$j = 0;
			$node[$i]['children'][$j]['attr']['id'] = 'exe_1';
			$node[$i]['children'][$j]['attr']['rel'] = 'import';
			$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('product')).' - '.ucfirst($txt->getWord('import'));
			$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/import_16.gif';
			$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=exe&type=0';
			$j++;
			$node[$i]['children'][$j]['attr']['id'] = 'exe_2';
			$node[$i]['children'][$j]['attr']['rel'] = 'import';
			$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('product')).' - '.ucfirst($txt->getWord('export'));
			$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/import_16.gif';
			$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=exe&type=1';
			
			$i++;
		}
		
		//if($shop->getGlobalSetting('shipping'))
		//{
			$node[$i]['attr']['id'] = 'shipping';
			$node[$i]['attr']['rel'] = 'shipping';
			$node[$i]['data']['title'] = ucfirst($txt->getWord('shipping_methods'));
			$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_pack_16.gif';
			$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=shipping';
			$j = 0;
			if($shop->getShopShippingMethods())
			{
				foreach($shop->getShopShippingMethods() as $item)
				{
					$node[$i]['children'][$j]['attr']['id'] = 'shipping_'.$item['id'];
					$node[$i]['children'][$j]['attr']['rel'] = 'shipping_method';
					$node[$i]['children'][$j]['data']['title'] = $item['title'];
					$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/shipping_16.gif';
					$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&shipping='.$item['id'].'';
					$j++;
				}
			}
			$i++;
		//}
		
		if($shop->getGlobalSetting('provider'))
		{
			$node[$i]['attr']['id'] = 'provider';
			$node[$i]['attr']['rel'] = 'providers';
			$node[$i]['data']['title'] = ucfirst($txt->getWord('providers')).' ('.intval(count($shop->getProviders())).')';
			$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/contacts_16.gif';
			$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=provider';
			$j = 0;
			if(($shop->getProviders()) && (count($shop->getProviders()) < 51))
			{
				foreach($shop->getProviders() as $item)
				{
					$node[$i]['children'][$j]['attr']['id'] = 'provider_'.$item->getId();
					$node[$i]['children'][$j]['attr']['rel'] = 'provider';
					$node[$i]['children'][$j]['data']['title'] = $item->getTitle();
					$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/file_doc_16.gif';
					$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&provider='.$item->getId().'';
					$j++;
				}
			}
			$i++;
		}
		
		if($shop->getGlobalSetting('brand'))
		{
			$node[$i]['attr']['id'] = 'brand';
			$node[$i]['attr']['rel'] = 'brands';
			$node[$i]['data']['title'] = ucfirst($txt->getWord('brands')).' ('.intval(count($shop->getBrands())).')';
			$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/brands_16.png';
			$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=brand';
			$j = 0;
			if(($shop->getBrands()) && (count($shop->getBrands()) < 51))
			{
				foreach($shop->getBrands() as $item)
				{
					$node[$i]['children'][$j]['attr']['id'] = 'brand_'.$item->getId();
					$node[$i]['children'][$j]['attr']['rel'] = 'brand';
					$node[$i]['children'][$j]['data']['title'] = $item->getTitle();
					$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/brands_16.png';
					$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&brand='.$item->getId().'';
					$j++;
				}
			}
			$i++;
		}
		
		if($shop->getGlobalSetting('groups'))
		{
			$node[$i]['attr']['id'] = 'grp';
			$node[$i]['attr']['rel'] = 'groups';
			$node[$i]['data']['title'] = ucfirst($txt->getWord('productgroups')).' ('.intval(count($shop->getGroups())).')';
			$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_red_16.gif';
			$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=grp';
			$i++;
		}
		
		if($shop->getGlobalSetting('categories'))
		{
			$node[$i]['attr']['id'] = 'cat';
			$node[$i]['attr']['rel'] = 'categories';
			$node[$i]['data']['title'] = ucfirst($txt->getWord('categories')).' ('.intval(count($shop->getCats())).')';
			$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_blue_16.gif';
			$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=cat';
			$i++;
		}
		
		if($shop->getGlobalSetting('attributes'))
		{
			$node[$i]['attr']['id'] = 'attributes';
			$node[$i]['attr']['rel'] = 'attributes';
			$node[$i]['data']['title'] = ucfirst($txt->getWord('attributes')).' ('.intval(count($shop->getProductAttributes())).')';
			$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_green_16.gif';
			$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=attributes';
			$j = 0;
			if(($shop->getProductAttributes()) && (count($shop->getProductAttributes()) < 51))
			{
				foreach($shop->getProductAttributes() as $item)
				{
					$node[$i]['children'][$j]['attr']['id'] = 'attribute_'.$item->getId();
					$node[$i]['children'][$j]['attr']['rel'] = 'attribute';
					$node[$i]['children'][$j]['data']['title'] = $item->getTitle();
					$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/object_16.gif';
					$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&attribute='.$item->getId().'';
					$j++;
				}
			}
			$i++;
		}
		
		$node[$i]['attr']['id'] = 'orders';
		$node[$i]['attr']['rel'] = 'orders';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('orders'));
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/package_16.gif';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=orders';
		$j = 0;
		$node[$i]['children'][$j]['attr']['id'] = 'orders_status_1';
		$node[$i]['children'][$j]['attr']['rel'] = 'orders_status';
		$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('new_orders')).' - ('.$shop->getOrdersNewCount().')';
		$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/package_16.gif';
		$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=orders&status=0';
		$j++;
		$node[$i]['children'][$j]['attr']['id'] = 'orders_status_2';
		$node[$i]['children'][$j]['attr']['rel'] = 'orders_status';
		$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('pending')).' - ('.$shop->getOrdersPendingCount().')';
		$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/package_16.gif';
		$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=orders&status=1';
		$j++;
		$node[$i]['children'][$j]['attr']['id'] = 'orders_status_3';
		$node[$i]['children'][$j]['attr']['rel'] = 'orders_status';
		$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('orders_processed')).' - ('.$shop->getOrdersProcessedCount().')';
		$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/package_16.gif';
		$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=orders&status=2';
		$i++;
		
		$node[$i]['attr']['id'] = 'report';
		$node[$i]['attr']['rel'] = 'report';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('reports'));
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/survey_16.gif';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=report&report=orders';
		
		$j = 0;
		$node[$i]['children'][$j]['attr']['id'] = 'report_orders';
		$node[$i]['children'][$j]['attr']['rel'] = 'report_orders';
		$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('sale')).' - '.ucfirst($txt->getWord('orders'));
		$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/stat_16.gif';
		$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=report&report=orders';
		$j++;
		$node[$i]['children'][$j]['attr']['id'] = 'report_products';
		$node[$i]['children'][$j]['attr']['rel'] = 'report_products';
		$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('sale')).' - '.ucfirst($txt->getWord('products'));
		$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/stat_16.gif';
		$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=report&report=products';
		$j++;
		$node[$i]['children'][$j]['attr']['id'] = 'report_zones';
		$node[$i]['children'][$j]['attr']['rel'] = 'report_zones';
		$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('sale')).' - '.ucfirst($txt->getWord('shipping').' '.$txt->getWord('zone'));
		$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/stat_16.gif';
		$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=report&report=zones';
		$j++;
		$node[$i]['children'][$j]['attr']['id'] = 'report_production';
		$node[$i]['children'][$j]['attr']['rel'] = 'report_production';
		$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('production_list'));
		$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/stat_16.gif';
		$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=report&report=production';
		$j++;
		if($shop->getGlobalSetting('questions'))
		{
			$node[$i]['children'][$j]['attr']['id'] = 'report_questions';
			$node[$i]['children'][$j]['attr']['rel'] = 'report_questions';
			$node[$i]['children'][$j]['data']['title'] = ucfirst($txt->getWord('surveys'));
			$node[$i]['children'][$j]['data']['icon'] = SYSICONS_URL.'treemenu/survey_16.gif';
			$node[$i]['children'][$j]['data']['attr']['href'] = '?con='.$con.'&list=report&report=response';
			$j++;
		}
		
		$i++;
		
		$node[$i]['attr']['id'] = 'product';
		$node[$i]['attr']['rel'] = 'products';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('products')).' ('.intval(count($shop->getCats())).')';
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/folder_blue_16.gif';
		$node[$i]['data']['attr']['href'] = '?con='.$con;
		
		$sitemap	= $siteAdmin->getSitemapTree(SITE_ID, 0);
		$node[$i]['children'] = getSitemapSubitemsJSON($sitemap, $con, 'shop_');
		$i++;
		
        return $node;
    }
	
	function getSurveySubitemsJSON($con)
    {
		/*
		global $siteAdmin;
		global $commander;
		global $katana;
		global $surveyCore;
		
		$i = 0;
		$surveyCore->loadShipList();
		if(count($fleet->getShipList()) > 0)
		{
			foreach($fleet->getShipList() as $item)
			{
				$node[$i]['attr']['id'] = 'ship_'.$item->getId();
				$node[$i]['attr']['rel'] = 'ship';
				$node[$i]['data']['title'] = $item->getTitle();
				$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/object_16.gif';
				$node[$i]['data']['attr']['href'] = '?con='.$con.'&shipping='.$item->getId().'';
				$i++;
			}
		}
        return $node; */
    }
	
	function getFleetSubitemsJSON($con)
    {
		global $fleet;
		$i = 0;
		
		$fleet->loadShipList();
		if(count($fleet->getShipList()) > 0)
		{
			foreach($fleet->getShipList() as $item)
			{
				$node[$i]['attr']['id'] = 'ship_'.$item->getId();
				$node[$i]['attr']['rel'] = 'ship';
				$node[$i]['data']['title'] = $item->getTitle();
				$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/object_16.gif';
				$node[$i]['data']['attr']['href'] = '?con='.$con.'&shipping='.$item->getId().'';
				$i++;
			}
		}
        return $node;
    }
	
	function getAcessControllSubitemsJSON($con)
    {
		global $katana;
		global $commander;
		global $txt;
		
		$i = 0;
		$node[$i]['attr']['id'] = 'users';
		$node[$i]['attr']['rel'] = 'users';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('users'));
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/users_16.png';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=user';
		$i++;
		
		$node[$i]['attr']['id'] = 'grp';
		$node[$i]['attr']['rel'] = 'groups';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('user_groups'));
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/users_16.png';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=group';
		$i++;
		
		$node[$i]['attr']['id'] = 'levels';
		$node[$i]['attr']['rel'] = 'levels';
		$node[$i]['data']['title'] = ucfirst($txt->getWord('access_levels'));
		$node[$i]['data']['icon'] = SYSICONS_URL.'treemenu/users_16.png';
		$node[$i]['data']['attr']['href'] = '?con='.$con.'&list=level';
		$i++;
		
        return $node;
    }
	
	echo json_encode(getMenuTree());
	
	exit();
	
?>